import instance from '@/utils/request'

export function getUser (page, pageSize, name = '', gender = '', begin = '', end = '') {
  return instance.get(`/api/user?page=${page}&pageSize=${pageSize}&name=${name}&gender=${gender}&begin=${begin}&end=${end}`)
}

export function addUser (from) {
  return instance.post('/api/user', {
    name: from.name,
    password: from.password,
    gender: from.gender,
    class1: from.class1,
    studentNumber: from.studentNumber,
    phone: from.phone,
    jurisdiction: from.jurisdiction ? 1 : 0
  })
}

export function changeUser (from) {
  console.log(from.jurisdiction)
  return instance.put('/api/user', {
    id: from.id,
    name: from.name,
    password: from.password,
    gender: from.gender,
    class1: from.class1,
    studentNumber: from.studentNumber,
    phone: from.phone,
    jurisdiction: from.jurisdiction ? 1 : 0
  })
}

export function deleteUser (idList) {
  const str = '/api/user/' + idList.map(item => item)
  return instance.delete(str)
}

export function changeUserJurisdiction (id, res) {
  return instance.put('/api/user/jurisdiction/' + res + '/' + id)
}
